<template>
	<view class="p-20 bg-white pages">

		<!-- 标题 -->
		<view>
			<text class="fw fs-36">{{item.title || ''}}</text>
		</view>
		<!-- end -->

		<view class="mt-30 c-666 flex ac sb">
			<view>
				<text>{{$timer.formatTime(item.create_time)}}</text>
				<text class="ml-20">{{item.admin.nickname || ''}}</text>
			</view>
			<view>
				<text>阅读：</text>
				<text>{{item.number || 0}}</text>
			</view>
		</view>

		<!-- 富文本 -->
		<view class="mt-50">
			<jyf-parser :html="item.text.replace(/<br\/>/ig, '')" ref="article"></jyf-parser>
		</view>
		<!-- end -->

	</view>
</template>

<script>
	import {
		configMap
	} from "@/utils";
	import {
		mapGetters
	} from "vuex";
	import {
		newDetail
	} from '@/api/extend.js'
	import parser from "@/components/jyf-parser/jyf-parser";
	export default {
		components: {
			"jyf-parser": parser,
		},
		computed: {
			...configMap({}, mapGetters(['isLogin', 'uid', 'userInfo'])),
			chamberObj() {
				return this.$store.state.extend.chamberObj
			},
		},
		// #ifdef MP
		onShareAppMessage: function() {
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			})
			return {
				title: `${this.chamberObj.nickname}\r\n${this.item.title}` || '',
				path: `pages/extend/chamber/news_details?uid=${this.uid || -1}&nid=${this.newId}`,
			}
		},
		onShareTimeline: function() {
			return {
				title: `${this.chamberObj.nickname}\r\n${this.item.title}` || '',
				query: {
					uid: this.uid,
				},
				imageUrl: ''
			}
		},
		// #endif
		data() {
			return {
				chamber_id:'',
				newId: '',
				item: {
					text: ''
				},
			}
		},
		methods:{
			getcomDetailFunc() {
				comDetail({
					com_id: this.chamber_id
				}).then(res => {
					this.$store.commit('SET_ChamberObj', res.data);
				}).catch(err => {
					uni.showToast({
						title: err,
						icon: 'none'
					})
				})
			},
		},
		onLoad(options) {
			this.newId = options.nid;
			this.chamber_id = options.cid;
			if(!this.chamberObj.nickname){
				this.getcomDetailFunc();
			}
			newDetail({
				id: this.newId
			}).then(res => {
				this.item = res.data;
			})
		}
	}
</script>

<style lang="scss" scoped>
	.pages {
		width: 100%;
		min-height: 100vh;
	}
</style>